package com.ymatou.iapi.pushbind.testcase;

import com.google.gson.JsonObject;
import com.ymatou.iapi.pushbind.parameter.GetSellerUserPushConfigInfoBean;
import com.ymatou.iapi.pushbind.parameter.SaveSellerPushConfigBean;
import com.ymatou.iapi.pushbind.service.GetSellerUserPushConfigInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.PushCallService;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Random;

/**
*获取买手推送配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSellerUserPushConfigInfo{
	private static GetSellerUserPushConfigInfoBean getselleruserpushconfiginfoBean;
	private static GetSellerUserPushConfigInfoCall getselleruserpushconfiginfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手推送配置");
	}

	@Before
	public void caseUp() {
		getselleruserpushconfiginfoBean=new GetSellerUserPushConfigInfoBean();
		getselleruserpushconfiginfoCall=new GetSellerUserPushConfigInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getselleruserpushconfiginfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerUserPushConfigInfo_001() {
		Logger.start(true,"获取买手推送配置");
		try {
			int userid = new Random().nextInt(10000);
			SaveSellerPushConfigBean saveSellerPushConfigBean =	PushCallService.initSaveSellerPushConfig(userid);
			PushCallService.saveSellerPushConfig(saveSellerPushConfigBean);
			getselleruserpushconfiginfoBean.setUserId(userid);
			getselleruserpushconfiginfoBean.setClientId(saveSellerPushConfigBean.getConfigInfo().getClientId());
			getselleruserpushconfiginfoCall.setData(getselleruserpushconfiginfoBean);
			getselleruserpushconfiginfoCall.callService();			
			Logger.verifyEquals("200",getselleruserpushconfiginfoCall.getString("Status"),"验证Status");
			JsonObject jet = getselleruserpushconfiginfoCall.getJsonObject().get("Result").getAsJsonObject().get("ConfigInfo").getAsJsonObject();
			Logger.verifyEquals(userid,jet.get("UserId").getAsInt(),"验证UserId");
			Logger.verifyEquals(saveSellerPushConfigBean.getConfigInfo().getClientId(),jet.get("ClientId").getAsString(),"验证ClientId");
			Logger.verifyEquals(saveSellerPushConfigBean.getConfigInfo().getOrderStatusSwitch(),jet.get("OrderStatusSwitch").getAsInt(),"验证OrderStatusSwitch");
			Logger.verifyEquals(saveSellerPushConfigBean.getConfigInfo().getInteractiveMsgSwitch(),jet.get("InteractiveMsgSwitch").getAsInt(),"验证InteractiveMsgSwitch");
			Logger.verifyEquals(saveSellerPushConfigBean.getConfigInfo().getTransactionSwitch(),jet.get("TransactionSwitch").getAsInt(),"验证TransactionSwitch");
			Logger.verifyEquals(saveSellerPushConfigBean.getConfigInfo().getSocialMessageSwitch(),jet.get("SocialMessageSwitch").getAsInt(),"验证SocialMessageSwitch");
			Logger.verifyEquals(saveSellerPushConfigBean.getConfigInfo().getOrderUnPaySwitch(),jet.get("OrderUnPaySwitch").getAsInt(),"验证OrderUnPaySwitch");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerUserPushConfigInfo_002() {
		Logger.start(true,"获取买手推送配置，userId为空");
		try {
			int userid = new Random().nextInt(10000);
			SaveSellerPushConfigBean saveSellerPushConfigBean =	PushCallService.initSaveSellerPushConfig(userid);
			PushCallService.saveSellerPushConfig(saveSellerPushConfigBean);
			getselleruserpushconfiginfoBean.setClientId(saveSellerPushConfigBean.getConfigInfo().getClientId());
			getselleruserpushconfiginfoCall.setData(getselleruserpushconfiginfoBean);
			getselleruserpushconfiginfoCall.callService();
			Logger.verifyEquals("406",getselleruserpushconfiginfoCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerUserPushConfigInfo_003() {
		Logger.start(true,"获取买手推送配置,clientId为空");
		try {
			int userid = new Random().nextInt(10000);
			SaveSellerPushConfigBean saveSellerPushConfigBean =	PushCallService.initSaveSellerPushConfig(userid);
			PushCallService.saveSellerPushConfig(saveSellerPushConfigBean);
			getselleruserpushconfiginfoBean.setUserId(userid);
			getselleruserpushconfiginfoCall.setData(getselleruserpushconfiginfoBean);
			getselleruserpushconfiginfoCall.callService();
			Logger.verifyEquals("406",getselleruserpushconfiginfoCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}